// Copyright (c) 2023 Presto Labs Pte. Ltd.
// Author: tianqiang

#pragma once

#include <string>
#include <unordered_set>

namespace coin2::exchange::base::order {

class UnknownIdManagerGuard;

class UnknownIdManager {
 public:
  friend class UnknownIdManagerGuard;

  UnknownIdManager() {}
  UnknownIdManager(const UnknownIdManager& manager) = delete;
  UnknownIdManager& operator=(const UnknownIdManager& manager) = delete;

  UnknownIdManagerGuard GetGuard();

 private:
  bool IsNeedLog(const std::string& symbol, const std::string& id);

  std::unordered_set<std::string> unknown_logged_ids_;
  std::unordered_set<std::string> known_symbols_;
};

class UnknownIdManagerGuard {
 public:
  friend class UnknownIdManager;

  bool IsNeedLog(const std::string& symbol, const std::string& id);

  ~UnknownIdManagerGuard();
  UnknownIdManagerGuard(const UnknownIdManagerGuard& guard) = delete;
  UnknownIdManagerGuard& operator=(const UnknownIdManagerGuard& guard) = delete;

 private:
  UnknownIdManagerGuard(UnknownIdManager& manager);

  UnknownIdManager& manager_;
  std::unordered_set<std::string> known_symbols_tmp_;
};

}  // namespace coin2::exchange::base::order
